package com.siwei.infoextract.rule;

import java.util.regex.Matcher;

import com.siwei.infoextract.wrapper.featureextract.AnnotationOutputter;
import com.siwei.infoextract.wrapper.featureextract.InnerTextFeatureExtractor;
import com.siwei.infoextract.wrapper.parser.DomNode;

public class IsAddressPatternCriteria extends Criteria {
	public IsAddressPatternCriteria(String criteriaName, String criteriaValue) {
		super(criteriaName, criteriaValue);
	}

	public boolean doAction(DomNode domNode) {
		// do nothing in the super class
		InnerTextFeatureExtractor innerTextExtractor = new InnerTextFeatureExtractor();
		String innerText =  (String)innerTextExtractor.extract(domNode);

		Matcher matcher = AnnotationOutputter.addressPattern.matcher(innerText);

		boolean patternMatched = false;
		if (matcher.find()) {
			patternMatched = true;
		}

		boolean value = Boolean.parseBoolean(criteriaValue);
		return value == patternMatched;
	}
}
